package vg.services.data_base_manager.interfaces;

import java.util.List;
import java.util.Map;
import java.util.Set;

import vg.services.data_base_manager.data.graph.Attribute;
import vg.services.data_base_manager.data.graph.Edge;
import vg.services.data_base_manager.data.graph.Graph;
import vg.services.data_base_manager.data.graph.Vertex;
import vg.services.data_base_manager.data.header.AttributeHeader;
import vg.services.data_base_manager.data.header.GraphHeader;
import vg.services.data_base_manager.data.header.GraphModelHeader;
import vg.services.data_base_manager.data.header.VertexHeader;
import vg.services.data_base_manager.data.skeleton.GraphTreeElement;

public interface IModel {
//=============================================================================
//-----------------Methods for graph creating----------------------------------
	/**
	 * Creates header for the graph model and returns the unique id.
	 * @param name - name of the graph.
	 */
	public int createGraphModelHeader(String name);

	/**
	 * Creates header for the graph model and create directed root graph.
	 */
	public int createGraphModelHeaderWithEmptyRootGraph(String name);
	
	/**
	 * Creates header for the graph and returns the unique id.
	 * @param graphModelId - id of graph model, which will contains the graph. 
	 * @param directed - true - if the subgraph - directed, otherwise false.
	 */
	public int createGraphHeader(int graphModelId, boolean directed);
	
	/**
	 * Creates header for the vertex and returns the unique id.
	 * @param graphId - id of graph, which will contains the vertex.
	 * @param link2inner_graph - link to subgraph, which is in this vertex.
	 */
	public int createVertexHeader(int graphId, int link2inner_graph);
	
	/**
	 * Creates header for the edge and returns the unique id.
	 * Warning: this method doesn't verify the correctness of input data.
	 * @param subgraph_id - id of subgraph, which will contain the edge.
	 * @param source_id - id of source vertex.
	 * @param target_id - id of target vertex.
	 */
	public int quickCreateEdgeHeader(int subgraph_id, int source_id, int target_id);
	
	/**
	 * Creates header for the edge and returns the unique id.
	 * @param subgraph_id - id of subgraph, which will contain the edge.
	 * @param source_id - id of source vertex.
	 * @param target_id - id of target vertex.
	 */
	public int createEdgeHeader(int subgraph_id, int source_id, int target_id);
	
	/**
	 * Creates header for the attribute and returns the unique id.
	 * @param edge_id - id of edge, which will contain the attribute. 
	 */
	public int createAttributeHeader4Edge(int edge_id, String name, Object value, Class<?> type);
	
	/**
	 * Creates header for the attribute and returns the unique id.
	 * @param edge_id - id of vertex, which will contain the attribute. 
	 */
	public int createAttributeHeader4Vertex(int vertex_id, String name, Object value, Class<?> type);
	
	/**
	 * This method returns subgraph is builded from list of vertexes.
	 * @param vertexIds - list of vertex id's.
	 */
	public Graph getSubGraph(List<Integer> vertexIds);
	
	/**
	 * This method returns graph by id.
	 */
	public Graph getGraph(int graphId);
	
	/**
	 * This method returns root graph.
	 * @param graphModelId - id of graph model.
	 */
	public Graph getRootGraphByGraphModelId(int graphModelId);
	
	/**
	 * This method returns edge.
	 * @param edgeId - id of edge.
	 */
	public Edge getEdge(int edgeId);
	
	/**
	 * This method returns vertex.
	 * @param vertexId - id of vertex.
	 */
	public Vertex getVertex(int vertexId);
	
	/**
	 * This method returns attribute.
	 * @param attrId - id of attribute.
	 */
	public Attribute getAttribute(int attrId);
	
	/**
	 * This method returns graph model header with id = graphModelId.
	 */
	public GraphModelHeader getGraphModelHeader(int graphModelId);
	
	/**
	 * This method returns graph model ids.
	 */
	public List<Integer> getGraphModelIds();

	/**
	 * This method returns graph model header with id = graphId.
	 */
	public GraphHeader getGraphHeader(int graphId);

	/**
	 * Returns vertex header with id = vertexId.
	 */
	public VertexHeader getVertexHeader(int vertexId);

	/**
	 * Returns vertex header with id = attributeId.
	 */
	public AttributeHeader getAttributeHeader(int attributeId);
	
	/**
	 * This method returns graph header for vertex. 
	 */
	public GraphHeader getGraphHeader4Vertex(int vertexId);
		
	/**
	 * This method called before program closing  
	 */
	public void quit();
	
	/**
	 * This method is resetting model.  
	 */
	public void resetModel();
	
	/**
	 * This method closes a graph.
	 * @param graphId - id of graph, which we want to close.
	 */	
	public void closeGraph(int grapgId);
	
	/**
	 * This methods executes SQL request and returns ResultSet.
	 */
	public List<List<Object>> executeSQLRequest(String request);
	
	/**
	 * This method returns graph model skeleton.
	 */
	public GraphTreeElement getGraphModelSkeleton(int graphModelId);
	
	public Set<Integer> getAllVertexIds4SubGraph(Graph subGraph);
	public Set<Integer> getAllVertexIds4Graph(int graphId);
//=============================================================================
//--------------Modifying methods----------------------------------------------
	/**
	 * This method modifies graph model with id = newGraphModelHeader.id.
	 */
	public boolean modifyGraphModelHeader(GraphModelHeader newGraphModelHeader);
	
	/**
	 * This method modifies vertex with id = newVertexHeader.id.
	 */
	public boolean modifyVertexHeader(VertexHeader newVertexHeader);
	
	/**
	 * This method modifies attribute with id = newAttributeHeader.id.
	 */
	public boolean modifyAttributeHeader(AttributeHeader newAttributeHeader);
	
//=============================================================================
//--------------OTHER METHODS----------------------------------------------
	/**
	 * Generates title for subgraph.
	 * Returns <b>title</b>, if this method found subgraph or his components in
	 * database, otherwise <b>null</b>.  
	 */
	public String generateTitle4SubGraph(Graph subGraph);

	public int generateGraphId4SubGraph(Graph subGraph);
	
	public int generateSubGraphId4SubGraph(Graph subGraph);

//=============================================================================
//--------------Methods for working with attributes----------------------------
	/**
	 * Returns map, where key is attribute's name, 
	 * and value is attribute's type for all vertices of graph model.
	 * 
	 * If attribute's name has more than one value, that 
	 * attribute's type is String.class.
	 */
	public Map<String, Class<?>> getVertexAttributes4GraphModel(int graphModelId);

	/**
	 * Returns map, where key is attribute's name, 
	 * and value is attribute's type for all edges of graph model.
	 * 
	 * If attribute's name has more than one value, that 
	 * attribute's type is String.class.
	 */
	public Map<String, Class<?>> getEdgeAttributes4GraphModel(int graphModelId);
}
